import request from './axios';

/**
 * 消息相关API
 */
export const messageApi = {
  /**
   * 获取护工的消息列表
   * @param {number} caregiverId - 护工ID
   * @param {number} messageType - 消息类型（可选）
   * @param {number} status - 消息状态（可选）
   * @returns {Promise}
   */
  getMessagesByCaregiver(caregiverId, messageType = null, status = null) {
    const params = {};
    if (messageType !== null) params.messageType = messageType;
    if (status !== null) params.status = status;
    
    return request({
      url: `/api/messages/caregiver/${caregiverId}`,
      method: 'get',
      params
    });
  },

  /**
   * 获取消息统计信息
   * @param {number} caregiverId - 护工ID
   * @returns {Promise}
   */
  getMessageStatistics(caregiverId) {
    return request({
      url: `/api/messages/statistics/${caregiverId}`,
      method: 'get'
    });
  },

  /**
   * 标记消息为已读
   * @param {number} messageId - 消息ID
   * @returns {Promise}
   */
  markAsRead(messageId) {
    return request({
      url: `/api/messages/read/${messageId}`,
      method: 'put'
    });
  },

  /**
   * 批量标记消息为已读
   * @param {Array} messageIds - 消息ID列表
   * @returns {Promise}
   */
  batchMarkAsRead(messageIds) {
    return request({
      url: '/api/messages/batch-read',
      method: 'put',
      data: messageIds
    });
  },

  /**
   * 发送前台通知（老人入住分配）
   * @param {Object} params - 参数对象
   * @param {number} params.caregiverId - 护工ID
   * @param {number} params.elderId - 老人ID
   * @param {string} params.elderName - 老人姓名
   * @param {string} params.receptionName - 前台姓名
   * @returns {Promise}
   */
  sendReceptionNotification(params) {
    return request({
      url: '/api/messages/reception-notification',
      method: 'post',
      params
    });
  },

  /**
   * 发送家属消息
   * @param {Object} params - 参数对象
   * @param {number} params.caregiverId - 护工ID
   * @param {number} params.familyMemberId - 家属ID
   * @param {string} params.familyMemberName - 家属姓名
   * @param {number} params.elderId - 老人ID
   * @param {string} params.elderName - 老人姓名
   * @param {string} params.content - 消息内容
   * @returns {Promise}
   */
  sendFamilyMessage(params) {
    return request({
      url: '/api/messages/family-message',
      method: 'post',
      params
    });
  },

  /**
   * 发送管理员通知
   * @param {Object} params - 参数对象
   * @param {number} params.caregiverId - 护工ID
   * @param {number} params.adminId - 管理员ID
   * @param {string} params.adminName - 管理员姓名
   * @param {string} params.title - 标题
   * @param {string} params.content - 内容
   * @param {number} params.priority - 紧急程度
   * @returns {Promise}
   */
  sendAdminNotification(params) {
    return request({
      url: '/api/messages/admin-notification',
      method: 'post',
      params
    });
  }
};
// 缺失接口补充
export const getCaregiverMessages = (params) => request.get('/message/caregiver', { params })
export const markMessageAsRead = (id) => request.put(`/message/read/${id}`)
export const deleteMessage = (id) => request.delete(`/message/${id}`)
export const sendMessage = (data) => request.post('/message', data)
export const getFamilyMessages = (params) => request.get('/message/family', { params })
export const sendMessageToCaregiver = (data) => request.post('/message/to-caregiver', data)
export const getCaregiversByElder = (elderId) => request.get(`/message/caregivers/${elderId}`)
export const getReceptionMessages = (params) => request.get('/message/reception', { params })
export const sendReceptionMessage = (data) => request.post('/message/reception', data)
export const deleteMessageById = (id) => request.delete(`/message/${id}`)